package com.ls.fw.mvc.springmvc.util;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.springframework.web.context.request.WebRequest;

public class WebUitls {

	public static Map<String,Object> getAllPara(WebRequest  request){
		Iterator<String> pNames =  request.getParameterNames();
		Map<String, Object> params = new HashMap<String, Object>();
		while (pNames.hasNext()) {
			String pName = (String) pNames.next();
			Object pValue = request.getParameter(pName);
			params.put(pName, pValue);
		}
		Map<String, String[]> paramMap = request.getParameterMap();
		Set<String> keySet = paramMap.keySet();
		for (Object objName : keySet) {
			String paramName = objName.toString();
			String[] values = (String[]) paramMap.get(objName);
			if (values != null && values.length == 1) { // 单值,多值不考虑

				params.put(paramName, values[0]);
			}else if(values != null && values.length > 1){
				params.put(paramName, Arrays.toString(values));
			}else{
				params.put(paramName, null);
			}
		}
		return params;
	}
}
